<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            width: 100vw;
            height: 100vh;
        }

        .root {
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .inner {
            width: 30%;
            height: 20%;
            /* background-color: red; */
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            align-items: center;
            justify-content: space-between;
        }

        h1 {
            width: 100%;
            text-align: center;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div class="root">
        <div class="inner">
            <h1>登录</h1>
            <div>
                用户名: <input type="text" id="username" />
            </div>
            <div>
                年龄: <input type="number" id="age" />
            </div>
            <div>
                密码: <input type="password" id="password" />
            </div>
            <button id="submit">注册</button>
            <button id="login">登录</button>
        </div>
    </div>

    <script>
        let username = document.querySelector('#username');
        let age = document.querySelector('#age');
        let password = document.querySelector('#password');
        let submit = document.querySelector('#submit');
        let login = document.querySelector('#login');

        submit.onclick = () => {
            axios.post('/api/register', {
                    name: username.value,
                    age: age.value,
                    password: password.value,
                })
                .then(res => {
                    console.log(res)
                })
                .catch(err => {
                    console.error(err);
                });
        }

        login.onclick = () => {
            axios.post('/api/login', {
                    name: username.value,
                    age: age.value,
                    password: password.value,
                })
                .then(res => {
                    console.log(res)
                })
                .catch(err => {
                    console.error(err);
                })
        }
    </script>
</body>

</html>